package DP1;

/**
 * 全排列1
 */
public class Main17 {
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        prem(arr,0,arr.length-1);
    }

    public static void prem(int[] arr, int p,int q){
        if(p == q){
            for (int i = 0; i <= p; i++) {
                System.out.print(arr[i] + " ");
            }
            System.out.println();
        }else{
            for (int i = p; i <= q ; i++) {
                swap(arr,p,i);
                prem(arr,p+1,q);
                swap(arr,p,i);
            }
        }
    }

    // 交换数组中位置i和位置j的元素
    public static void swap(int[] arr,int i,int j){
        int temp = arr[i];
        arr[i] = arr[j];
        arr[j] = temp;
    }





}
